var parentId = [];
$(function () {
    $.ajax({
        type: 'POST',
        dataType: "json",
        url: '/systemMenu/queryParentMenu',
        success: function (data) {
            var view = "";
            $.each(data, function (i, n) {//加载父类节点即一级菜单
                view += '<li class="layui-nav-item layui-nav-itemed"><a class="" href="' + n.url + '"  name="' + n.text + '"></a><dl class="layui-nav-child"></li>'
            });
            return parentId[i] = n.id;
        }
    });
    //异步加载子节点，即二级菜单
    $('.layui-nav[lay-filter="text"]').html({
        onSelect: function (title, index) {
            $("a[name='" + title + "']").text("");
            $.ajax({
                type: 'POST',
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                url: '/systemMenu/queryChildrenMenu?parentId=' + parentId[index],
                animate: true,
                success: function (data) {
                    $.each(data, function (i, n) {//加载二级菜单
                        $("ul[name='" + title + "']").append("<dd><a href='" + n.url + "'>n.text</a></dd>");
                    });
                    var dl = "</dl>";
                    $("ul[name='" + title + "']").append(dl);
                   /* $(".myTree").click(function () {
                        var url = $(this).data("url");
                        $("#Mytree").prop("src", url);
                    });*/
                }
            });
        }
    });
});